package cn.ibizlab.odoo.core.odoo_website.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iwebsite_published_mixin;
import cn.ibizlab.odoo.core.odoo_website.domain.Website_published_mixin;
import cn.ibizlab.odoo.core.odoo_website.filter.Website_published_mixinSearchContext;
import cn.ibizlab.odoo.core.odoo_website.service.IWebsite_published_mixinService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[网站发布Mixin] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Website_published_mixinServiceImpl implements IWebsite_published_mixinService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iwebsite_published_mixinClientService website_published_mixinClientService;

    @Override
    public Website_published_mixin get(Integer id) {
        Iwebsite_published_mixin clientModel = website_published_mixinClientService.createModel();
        clientModel.setId(id);
        website_published_mixinClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Website_published_mixin get(Website_published_mixin website_published_mixin) {
        Website_published_mixin retwebsite_published_mixin = this.get(website_published_mixin.getId()) ;
    	BeanCopier copier=BeanCopier.create(retwebsite_published_mixin.getClass(), website_published_mixin.getClass(), false);
        copier.copy(retwebsite_published_mixin, website_published_mixin, null);
        return website_published_mixin ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iwebsite_published_mixin clientModel = website_published_mixinClientService.createModel();
        clientModel.setId(id);
        website_published_mixinClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Website_published_mixin> website_published_mixins, int batchSize) {

        //website_published_mixinClientService.updateBatch(website_published_mixins,batchSize) ;

    }

    @Override
    public boolean create(Website_published_mixin website_published_mixin) {
        boolean bOk = false ;
        Iwebsite_published_mixin clientModel = this.convert2Model(website_published_mixin,null);
        website_published_mixinClientService.create(clientModel) ;
        this.convert2Domain(clientModel,website_published_mixin);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Website_published_mixin website_published_mixin) {
        boolean bOk = false ;
        Iwebsite_published_mixin clientModel = this.convert2Model(website_published_mixin,null);
        website_published_mixinClientService.update(clientModel) ;
        this.convert2Domain(clientModel,website_published_mixin) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Website_published_mixin> website_published_mixins, int batchSize) {

                        //website_published_mixinClientService.createBatch(website_published_mixins,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //website_published_mixinClientService.removeBatch(website_published_mixins) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Website_published_mixin> searchDefault(Website_published_mixinSearchContext context) {
        List<Website_published_mixin> list = new ArrayList<Website_published_mixin>();
        Page<cn.ibizlab.odoo.core.client.model.Iwebsite_published_mixin> clientModelList = website_published_mixinClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iwebsite_published_mixin clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Website_published_mixin>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Iwebsite_published_mixin convert2Model(Website_published_mixin domain , Iwebsite_published_mixin model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = website_published_mixinClientService.createModel() ;
        }

         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWebsite_publishedDirtyFlag())
            model.setWebsite_published(domain.getWebsite_published());
         if(domain.getIs_publishedDirtyFlag())
            model.setIs_published(domain.getIs_published());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getWebsite_urlDirtyFlag())
            model.setWebsite_url(domain.getWebsite_url());
        return model ;
    }

    public Website_published_mixin convert2Domain( Iwebsite_published_mixin model ,Website_published_mixin domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Website_published_mixin();
        }

        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWebsite_publishedDirtyFlag())
            domain.setWebsite_published(model.getWebsite_published());
        if(model.getIs_publishedDirtyFlag())
            domain.setIs_published(model.getIs_published());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getWebsite_urlDirtyFlag())
            domain.setWebsite_url(model.getWebsite_url());
        return domain ;
    }


}
